

package xyz.kongbai121.common.validator;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ArrayUtil;
import xyz.kongbai121.common.exception.RRException;
import org.apache.commons.lang.StringUtils;

import java.text.MessageFormat;
import java.util.List;
import java.util.Map;

/**
 * 数据校验
 *
 * @author Mark sunlightcs@gmail.com
 */
public abstract class Assert {

    public static void isBlank(String str, String message) {
        if (StringUtils.isBlank(str)) {
            throw new RRException(message);
        }
    }

    public static void isNull(Object object, String message) {
        if (object == null) {
            throw new RRException(message);
        }
    }

    public static void isArrayEmpty(Object[] array, String message) {
        if(ArrayUtil.isEmpty(array)){
            throw new RRException(message);
        }
    }

    public static void isListEmpty(List<?> list, String message) {
        if (CollUtil.isEmpty(list)) {
            throw new RRException(message);
        }
    }

    public static void isMapEmpty(Map map, String message) {
        if (MapUtil.isEmpty(map)) {
            throw new RRException(message);
        }
    }

    private static String msg(String message) {
//        return String.format("%s不能为空", message);
        return MessageFormat.format("{0}不能为空", message);
    }

}
